package com.zhoukai.controller.system;

import com.zhoukai.aspectj.annotation.Log;
import com.zhoukai.aspectj.enums.BusinessType;
import com.zhoukai.dto.DeptDto;
import com.zhoukai.service.DeptService;
import com.zhoukai.utils.ShiroSecurityUtils;
import com.zhoukai.vo.AjaxResult;
import com.zhoukai.vo.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author Mr.ZHOU
 * @Date Created in 2022/1/7 10:01
 */
@RestController
@RequestMapping("system/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    /**
     * 分页查询所有科室信息
     * @param deptDto
     * @return
     */
    @GetMapping("listDeptForPage")
    public AjaxResult listDeptForPage(DeptDto deptDto){
        DataGridView view = this.deptService.listDeptForPage(deptDto);
        return AjaxResult.success("查询成功",view.getData(),view.getTotal());
    }

    /**
     * 添加科室信息
     * @param deptDto
     * @return
     */
    @PostMapping("addDept")
    @Log(title = "科室管理-添加",businessType = BusinessType.INSERT)
    public AjaxResult addDept(@Validated DeptDto deptDto){
        deptDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(this.deptService.addDept(deptDto));
    }

    /**
     * 根据ID查询科室信息
     * @param deptId
     * @return
     */
    @GetMapping("getDeptById/{deptId}")
    public AjaxResult getDeptById(@PathVariable Long deptId){
        return AjaxResult.success(this.deptService.getDeptById(deptId));
    }

    /**
     * 根据ID删除科室信息
     * @param deptIds
     * @return
     */
    @DeleteMapping("deleteDeptByIds/{deptIds}")
    @Log(title = "科室管理-删除",businessType = BusinessType.DELETE)
    public AjaxResult deleteDeptByIds(@PathVariable Long[] deptIds){
        return AjaxResult.toAjax(this.deptService.deleteDeptByIds(deptIds));
    }

    /**
     * 修改科室信息
     * @param deptDto
     * @return
     */
    @PutMapping("updateDept")
    @Log(title = "科室管理-修改",businessType = BusinessType.UPDATE)
    public AjaxResult updateDept(@Validated DeptDto deptDto){
        deptDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(this.deptService.updateDept(deptDto));
    }

    /**
     * 查询所有可用科室信息不分页
     */
    @GetMapping("selectAllDept")
    public AjaxResult selectAllDept(){

        return AjaxResult.success(this.deptService.selectAllDept());
    }



}
